{% extends 'mobile/base.html' %}
{% load static%}

{% block mainbody %}
<style>
  /* 1. 页面基础样式 - 改为Tiffany蓝绿色主题 */
  :root {
    --color-primary: #0abab5; /* Tiffany蓝绿色主色 */
    --color-primary-light: #94d1be; /* 浅蓝绿交互色 */
    --color-primary-dark: #029191; /* 深蓝绿强调色 */
    --color-bg: #f0f7f4; /* 浅蓝绿背景 */
    --color-card: #ffffff; /* 卡片白 */
    --color-text-main: #1f2937; /* 主文本深灰 */
    --color-text-secondary: #6b7280; /* 次要文本中灰 */
    --color-text-light: #d1d5db; /* 辅助线浅灰 */
    --radius: 16px; /* 统一圆角 */
    --shadow: 0 4px 16px rgba(0,0,0,0.08); /* 轻阴影 */
    --transition: all 0.3s ease;
  }

  /* 移除默认边距解决顶部空白问题 */
  body {
    background-color: var(--color-bg);
    padding-bottom: 20px;
    margin: 0;
    padding-top: 0;
  }

  .content {
    padding: 10px;
    padding-top: 10px;
    margin-top: 0;
  }

  /* 2. 顶部用户信息卡片 */
  .user-card {
    background: linear-gradient(135deg, #0abab5 0%, #00a6a6 100%); /* Tiffany蓝渐变 */
    color: white;
    border-radius: var(--radius);
    padding: 24px 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    transition: transform 0.3s ease;
    margin-top: 0;
  }
  
  .user-card:hover {
    transform: translateY(-2px);
  }
  
  /* 装饰元素 - 改为水滴图案更符合Tiffany风格 */
  .user-card::before {
    content: "\f1cd";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    position: absolute;
    right: -10px;
    top: -10px;
    font-size: 80px;
    opacity: 0.1;
  }
  
  /* 首页按钮样式 - 融入用户卡片 */
  .home-button {
    position: absolute;
    top: 18px;
    right: 18px;
    background-color: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    backdrop-filter: blur(2px);
  }
  
  .home-button:hover {
    background-color: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
  }

  .user-info {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
  }
  
  .user-avatar {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.3);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255,255,255,0.1);
  }
  
  .user-avatar i {
    font-size: 32px;
    color: white;
  }
  
  .user-name {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 6px;
  }
  
  .user-tag {
    font-size: 13px;
    background-color: rgba(255,255,255,0.2);
    padding: 3px 10px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }
  
  .user-tag i {
    font-size: 10px;
  }
  
  /* 健康数据概览 - 优化对齐 */
  .health-overview {
    display: flex;
    justify-content: space-between;
    padding-top: 8px;
    border-top: 1px solid rgba(255,255,255,0.1);
    width: 100%;
    box-sizing: border-box;
  }
  
  .overview-item {
    text-align: center;
    flex: 1;
    min-width: -5;
    padding: 0 4px;
    position: relative;
  }
  
  .overview-item:not(:last-child)::after {
    content: "";
    position: absolute;
    right: 0;
    top: 10px;
    height: 30px;
    width: 1px;
    background-color: rgba(255,255,255,0.1);
  }
  
  .overview-value {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
  }
  
  .overview-value i {
    font-size: 14px;
    opacity: 0.8;
  }
  
  .overview-label {
    font-size: 12px;
    opacity: 0.9;
    word-wrap: break-word;
    line-height: 1.2;
  }

  /* 3. 功能菜单列表 */
  .menu-list {
    background-color: var(--color-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 16px;
    transition: var(--transition);
  }
  
  .menu-list:hover {
    box-shadow: 0 6px 20px rgba(0,0,0,0.1);
  }
  
  .menu-item {
    display: flex;
    align-items: center;
    padding: 16px 18px;
    border-bottom: 1px solid var(--color-text-light);
    color: var(--color-text-main);
    transition: var(--transition);
    cursor: pointer;
  }
  
  .menu-item:last-child {
    border-bottom: none;
  }
  
  .menu-item:hover {
    background-color: rgba(10, 186, 181, 0.05); /* Tiffany蓝 hover背景 */
    padding-left: 22px;
  }
  
  .menu-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-primary); /* Tiffany蓝图标 */
    font-size: 20px;
    margin-right: 14px;
    background-color: rgba(10, 186, 181, 0.1); /* Tiffany蓝背景 */
    border-radius: 8px;
  }
  
  .menu-text {
    flex: 1;
    font-size: 16px;
  }
  
  .menu-arrow {
    color: var(--color-text-light);
    font-size: 18px;
    transition: var(--transition);
  }
  
  .menu-item:hover .menu-arrow {
    color: var(--color-primary); /* Tiffany蓝箭头 */
    transform: translateX(3px);
  }

  /* 4. 近期饮食趋势卡片 */
  .trend-card {
    background-color: var(--color-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
    transition: var(--transition);
  }
  
  .trend-card:hover {
    box-shadow: 0 6px 20px rgba(0,0,0,0.1);
  }
  
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
  }
  
  .card-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--color-text-main);
    display: flex;
    align-items: center;
    gap: 8px;
  }
  
  .card-title i {
    color: var(--color-primary); /* Tiffany蓝图标 */
    font-size: 19px;
  }
  
  .card-more {
    font-size: 13px;
    color: var(--color-primary); /* Tiffany蓝文字 */
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: var(--transition);
    padding: 4px 8px;
    border-radius: 4px;
  }
  
  .card-more:hover {
    background-color: rgba(10, 186, 181, 0.1); /* Tiffany蓝背景 */
  }
  
  /* 趋势图表容器 */
  .trend-chart {
    width: 100%;
    height: 180px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding-bottom: 24px;
    position: relative;
  }
  
  .chart-axis {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 24px;
    border-top: 1px solid var(--color-text-light);
    display: flex;
    justify-content: space-between;
  }
  
  .axis-label {
    font-size: 12px;
    color: var(--color-text-secondary);
    transform: translateY(18px);
    font-weight: 500;
  }
  
  .chart-bar {
    flex: 1;
    background-color: var(--color-primary-light); /* Tiffany浅蓝绿柱状图 */
    border-radius: 6px 6px 0 0;
    transition: var(--transition);
    position: relative;
    opacity: 0;
    height: 0;
  }
  
  .chart-bar:hover {
    background-color: var(--color-primary); /* Tiffany蓝柱状图hover */
    transform: translateY(-3px);
  }
  
  .chart-value {
    position: absolute;
    top: -28px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    color: var(--color-text-secondary);
    white-space: nowrap;
    background-color: white;
    padding: 2px 6px;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    opacity: 0;
    transition: var(--transition);
  }
  
  .chart-bar:hover .chart-value {
    opacity: 1;
    top: -32px;
  }

  /* 5. 饮食偏好标签 */
  .preference-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
  }
  
  .tag-item {
    padding: 5px 14px;
    background-color: rgba(10, 186, 181, 0.1); /* Tiffany蓝背景 */
    color: var(--color-primary); /* Tiffany蓝文字 */
    border-radius: 18px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition);
  }
  
  .tag-item:hover {
    background-color: rgba(10, 186, 181, 0.2); /* Tiffany蓝深色背景 */
    transform: translateY(-2px);
  }
  
  .tag-item i {
    font-size: 11px;
  }

  /* 6. 响应式适配 */
  @media (max-width: 375px) {
    .user-card {
      padding: 20px 14px;
    }
    
    .user-avatar {
      width: 60px;
      height: 60px;
    }
    
    .overview-value {
      font-size: 16px;
    }
    
    .overview-label {
      font-size: 11px;
      letter-spacing: -0.5px;
    }
    
    .trend-chart {
      height: 150px;
    }
    
    .trend-chart {
      gap: 6px;
    }
  }
</style>

<!-- 主内容区 - 我的页面 -->
<div class="content">
  <!-- 1. 顶部用户信息卡片 -->
  <div class="user-card">
    <!-- 新增返回首页按钮 -->
    <button class="home-button" onclick="location.href='{% url 'mobile_index' %}'" title="返回首页">
      <i class="fas fa-home"></i>
    </button>

    <div class="user-info">
      <div class="user-avatar">
        <i class="fas fa-user"></i>
      </div>
      <div>
        <div class="user-name">
            {% if username %}
              {{ username }}  <!-- 优先显示后端传递的用户名 -->
            {% elif request.COOKIES.mobileuser %}
              {% if request.COOKIES.mobileuser|length == 11 and request.COOKIES.mobileuser|slice:":1" == "1" %}
                {{ request.COOKIES.mobileuser|slice:":3" }}****{{ request.COOKIES.mobileuser|slice:"-4:" }}  <!-- 手机号脱敏显示 -->
              {% else %}
                {{ request.COOKIES.mobileuser }}  <!-- 非手机号则直接显示（如账号） -->
              {% endif %}
            {% else %}
              健康饮食用户  <!-- 默认值，避免空白 -->
            {% endif %}
        </div>
        <div class="user-tag">
          <i class="fas 
            {% if user.has_autoimmune_disease == 1 %}fa-shield-alt
            {% elif user.has_hypertension == 1 %}fa-heart-pulse
            {% elif user.has_diabetes == 1 %}fa-tint
            {% elif user.has_hyperlipidemia == 1 %}fa-dna
            {% else %}fa-running
            {% endif %}
          "></i>
            {% if user.has_autoimmune_disease == 1 %}
              免疫调节人群 · 抗炎饮食目标
            {% elif user.has_hypertension == 1 %}
              高血压人群 · 低盐饮食目标
            {% elif user.has_diabetes == 1 and user.diabetes_type == 'type1' %}
              1型糖尿病人群 · 控碳水饮食目标
            {% elif user.has_diabetes == 1 and user.diabetes_type == 'type2' %}
              2型糖尿病人群 · 控糖控重目标
            {% elif user.has_diabetes == 1 and user.diabetes_type == 'gestational' %}
              妊娠糖尿病人群 · 营养控糖目标
            {% elif user.has_hyperlipidemia == 1 %}
              高血脂人群 · 低脂低胆目标
            {% else %}
              轻运动人群 · 均衡饮食目标
            {% endif %}
        </div>
      </div>
    </div>
    <!-- member.html 中健康概览部分 -->
<div class="health-overview">
  <div class="overview-item">
    <div class="overview-value">
      <i class="fas fa-check-circle"></i>
      {{ user.get_goal_achievement_rate|default:0 }}%
    </div>
    <div class="overview-label">目标达成率</div>
  </div>
  <div class="overview-item">
    <div class="overview-value">
      <i class="fas fa-fire"></i>
      1560kcal
    </div>
    <div class="overview-label">今日摄入</div>
  </div>
  <div class="overview-item">
    <div class="overview-value">
      <i class="fas fa-calendar-check"></i>
      {{ user.diet_records_count }}次
    </div>
    <div class="overview-label">总记录次数</div>
  </div>
  <div class="overview-item">
    <div class="overview-value">
      <i class="fas fa-thumbs-up"></i>
      {{ user.achieved_goals_count }}次
    </div>
    <div class="overview-label">推荐采纳</div>
  </div>
</div>
  </div>

  <!-- 2. 近期饮食趋势卡片 -->
  <div class="trend-card">
    <div class="card-header">
      <div class="card-title">
        <i class="fas fa-chart-line"></i>
        近7天热量摄入趋势
      </div>
      <div class="card-more" onclick="goToTrendDetail()">
        查看详情
        <i class="fas fa-angle-right"></i>
      </div>
    </div>
    <div class="trend-chart">
      <div class="chart-axis">
        <div class="axis-label">周一</div>
        <div class="axis-label">周二</div>
        <div class="axis-label">周三</div>
        <div class="axis-label">周四</div>
        <div class="axis-label">周五</div>
        <div class="axis-label">周六</div>
        <div class="axis-label">周日</div>
      </div>
      <div class="chart-bar" data-height="60%">
        <div class="chart-value">1480kcal</div>
      </div>
      <div class="chart-bar" data-height="75%">
        <div class="chart-value">1620kcal</div>
      </div>
      <div class="chart-bar" data-height="55%">
        <div class="chart-value">1420kcal</div>
      </div>
      <div class="chart-bar" data-height="80%">
        <div class="chart-value">1680kcal</div>
      </div>
      <div class="chart-bar" data-height="65%">
        <div class="chart-value">1520kcal</div>
      </div>
      <div class="chart-bar" data-height="90%">
        <div class="chart-value">1780kcal</div>
      </div>
      <div class="chart-bar" data-height="50%">
        <div class="chart-value">1380kcal</div>
      </div>
    </div>
    <div class="preference-tags">
      <div class="tag-item">
        <i class="fas fa-dumbbell"></i>
        高蛋白
      </div>
      <div class="tag-item">
        <i class="fas fa-oil-can"></i>
        低脂
      </div>
      <div class="tag-item">
        <i class="fas fa-leaf"></i>
        高纤维
      </div>
      <div class="tag-item">
        <i class="fas fa-cookie-bite"></i>
        少精制糖
      </div>
    </div>
  </div>

  <!-- 3. 功能菜单列表 -->
  <div class="menu-list">
    <div class="menu-item" onclick="goToDietRecord()">
      <div class="menu-icon">
        <i class="fas fa-utensils"></i>
      </div>
      <div class="menu-text">我的饮食记录</div>
      <div class="menu-arrow">
        <i class="fas fa-chevron-right"></i>
      </div>
    </div>
    <div class="menu-item" onclick="goToDietPlan()">
      <div class="menu-icon">
        <i class="fas fa-calendar-alt"></i>
      </div>
      <div class="menu-text">我的饮食计划</div>
      <div class="menu-arrow">
        <i class="fas fa-chevron-right"></i>
      </div>
    </div>
    <div class="menu-item" onclick="goToCollection()">
      <div class="menu-icon">
        <i class="fas fa-bookmark"></i>
      </div>
      <div class="menu-text">收藏的食谱</div>
      <div class="menu-arrow">
        <i class="fas fa-chevron-right"></i>
      </div>
    </div>
    <div class="menu-item" onclick="goToNutritionReport()">
      <div class="menu-icon">
        <i class="fas fa-chart-pie"></i>
      </div>
      <div class="menu-text">营养分析报告</div>
      <div class="menu-arrow">
        <i class="fas fa-chevron-right"></i>
      </div>
    </div>
  </div>

  <div class="menu-list">
    <div class="menu-item" onclick="goToUserInfo()">
      <div class="menu-icon">
        <i class="fas fa-user-cog"></i>
      </div>
      <div class="menu-text">个人信息设置</div>
      <div class="menu-arrow">
        <i class="fas fa-chevron-right"></i>
      </div>
    </div>
    <div class="menu-item" onclick="goToDietGoal()">
      <div class="menu-icon">
        <i class="fas fa-bullseye"></i>
      </div>
      <div class="menu-text">饮食目标设置</div>
      <div class="menu-arrow">
        <i class="fas fa-chevron-right"></i>
      </div>
    </div>
    <div class="menu-item" onclick="goToHelpCenter()">
      <div class="menu-icon">
        <i class="fas fa-question-circle"></i>
      </div>
      <div class="menu-text">帮助与反馈</div>
      <div class="menu-arrow">
        <i class="fas fa-chevron-right"></i>
      </div>
    </div>
    <div class="menu-item" style="cursor: pointer;" onclick="
    // 1. 显示确认框
    if(window.confirm('确定要退出登录吗？')){
        // 2. 创建隐藏表单
        const form = document.createElement('form');
        form.method = 'POST';
        // 3. 直接写死退出登录接口的绝对路径（必须替换为你的实际路径）
        form.action = '/mobile/logout/';
        
        // 4. 添加CSRF令牌（从当前页面cookie中获取）
        const csrf = document.createElement('input');
        csrf.type = 'hidden';
        csrf.name = 'csrfmiddlewaretoken';
        csrf.value = document.cookie.match(/csrftoken=([^;]+)/)[1];
        form.appendChild(csrf);
        
        // 5. 添加到页面并提交
        document.body.appendChild(form);
        form.submit();
        
        // 6. 强制清除所有相关痕迹
        document.cookie = 'mobileuser=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
        document.cookie = 'sessionid=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
        localStorage.clear();
        sessionStorage.clear();
        
        // 7. 强制跳转到登录页（必须替换为你的实际登录页路径）
        setTimeout(() => {window.location.href = '/mobile/login/';}, 100);
    }
">
    <div class="menu-icon">
        <i class="fas fa-sign-out-alt"></i>
    </div>
    <div class="menu-text">退出登录</div>
    <div class="menu-arrow">
        <i class="fas fa-chevron-right"></i>
    </div>
</div>
  </div>
</div>
{% endblock %}


<script>
  // 页面加载初始化
  document.addEventListener('DOMContentLoaded', function() {
    // 初始化图表动画
    initTrendChart();
  });

  // 趋势图表初始化（带动画效果）
  function initTrendChart() {
    const bars = document.querySelectorAll('.chart-bar');
    bars.forEach((bar, index) => {
      // 使用data属性存储高度值
      const height = bar.getAttribute('data-height');
      
      // 延迟动画，营造依次加载效果
      setTimeout(() => {
        bar.style.height = height;
        bar.style.opacity = '1';
      }, 100 * index);
    });
  }

  // 页面跳转逻辑
  function goToTrendDetail() {
    alert('即将跳转到热量摄入趋势详情页');
    // 实际项目中替换为真实跳转链接
    // location.href = '{% url 'mobile_trend_detail' %}';
  }

  function goToDietRecord() {
    alert('即将跳转到我的饮食记录页面');
    // location.href = '{% url 'mobile_diet_record' %}';
  }

  function goToDietPlan() {
    alert('即将跳转到我的饮食计划页面');
    // location.href = '{% url 'mobile_diet_plan' %}';
  }

  function goToCollection() {
    alert('即将跳转到收藏的食谱页面');
    // location.href = '{% url 'mobile_collection' %}';
  }

  function goToNutritionReport() {
    alert('即将跳转到营养分析报告页面');
    // location.href = '{% url 'mobile_nutrition_report' %}';
  }

  function goToUserInfo() {
    alert('即将跳转到个人信息设置页面');
    // location.href = '{% url 'mobile_user_info' %}';
  }

  function goToDietGoal() {
    alert('即将跳转到饮食目标设置页面');
    // location.href = '{% url 'mobile_diet_goal' %}';
  }

  function goToHelpCenter() {
    alert('即将跳转到帮助与反馈页面');
    // location.href = '{% url 'mobile_help_center' %}';
  }

</script>